package com.sun.test;

import org.junit.Test;

import java.text.DecimalFormat;
import java.util.*;

public class test07 {
    public static void main(String[] args) {
        List<Map<String, Object>> relist = new ArrayList();
        for (int i = 0; i < 3; i++) {
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("enforced", "100%");
            relist.add(map);
        }
        for (int i = 0; i < 3; i++) {
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("enforced", "50%");
            relist.add(map);
        }
        for (int i = 0; i < 3; i++) {
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("enforced", "70%");
            relist.add(map);
        }
        Collections.sort(relist, (o1, o2) -> {
            Double enforced1 = Double.valueOf(o1.get("enforced").toString().replace("%", ""));
            Double enforced2 = Double.valueOf(o2.get("enforced").toString().replace("%", ""));
            return -enforced1.compareTo(enforced2);
        });
        int rank = 1;
        for (int i = 0; i < relist.size(); i++) {
            if (i != 0 && ((Map) relist.get(i)).get("enforced").equals(((Map) relist.get(i - 1)).get("enforced"))) {
                // 如果执行率与前一名一样
                ((Map) relist.get(i)).put("rank", rank);
            } else {
                ((Map) relist.get(i)).put("rank", rank++);

            }
        }
        System.out.println(relist);
    }

    @Test
    public void DecimalFormattest() {
        double i = 0.5;
        DecimalFormat decimalFormat = new DecimalFormat("0.0");
        String format = decimalFormat.format(i);
        System.out.println(format);
    }

    @Test
    public void test02() {
        String s = "" + Integer.valueOf("30") / 60 + "";
        System.out.println(s);
    }

    @Test
    public void test03() {
        PersonSon personSon = new PersonSon();
        personSon.setName("hhh");
    }

    @Test
    public void test04() {
        Map<Integer, people> map = new HashMap();
        map.put(1, new man());
        map.put(2, new woman());
        testP(map.get(1));
    }

    @Test
    public void test05() {
        int[] nums = new int[]{3, 3};
        int tar = 6;
        int[] ints = twoSum(nums, tar);
        for (int anInt : ints) {
            System.out.println(anInt);
        }
    }


    public int[] twoSum(int[] nums, int target) {
        int[] arr = null;
        for (int i = 0; i < nums.length - 1; i++) {
            for (int j = i + 1; j < nums.length; j++) {
                int num = nums[i] + nums[j];
                if (num == target) {
                    arr = new int[]{i, j};
                    return arr;
                }
            }
        }
        return arr;
    }

    public int[] twoSum2(int[] nums, int target) {
        int[] arr = null;
        Map<Integer, Integer> map = new HashMap();
        for (int i = 0; i < nums.length; i++) {
            if (map.containsKey(target - nums[i])) {
                return arr = new int[]{map.get(target - nums[i]), nums[i]};
            }
            map.put(nums[i], i);
        }
        throw new IllegalArgumentException("未找到两个数");
    }


    public void testP(people people) {
        people.hello();
    }
}

class PersonSon {
    private String name;
    public static final String age = "15645132";

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public static String getAge() {
        return age;
    }

}

class man implements people {

    @Override
    public void hello() {
        System.out.println("manhello");
    }
}

class woman implements people {

    @Override
    public void hello() {
        System.out.println("womanhello");
    }


}